<?php

namespace App\Pool\Core;

class CoRedis
{
    protected $pool;

    public function __construct($pool)
    {
        $this->pool = $pool;
    }

    public function connection()
    {
        return $this->pool->get();
    }

    public function put($redis)
    {
        $this->pool->put($redis);
    }

    public function __call($name, $arguments)
    {
        try {
            $redisConnection = $this->connection();
            $redis           = new RedisCommand($redisConnection);
            $return          = $redis->$name(...$arguments);
            $this->put($redisConnection);
            return $return;
        } catch (\Exception $e) {
            $this->put(null);
            return $e->getMessage();
        }
    }
}